package _26define;

public class Demo1 {
    public static void main(String[] args) {
        new Thread(()->{
            synchronized (OBJECT){
                while (true){
                   if (i<= arr.length()){
                       if (isNumericZidai(arr.substring(i,i+1))){
                           System.out.println(i);
                           OBJECT.notify();
                           System.out.println(isNumericZidai(arr.substring(i,i+1)));
                           System.out.println(Thread.currentThread().getName()+arr.charAt(i));
                           i++;
                           System.out.println(i);
                       }else {
                           try {

                               OBJECT.wait();
                           } catch (InterruptedException e) {
                               e.printStackTrace();
                           }
                       }
                   }else break;
               }
                OBJECT.notify();
            }
        },"A").start();
        new Thread(()->{
            synchronized (OBJECT){
                while (true){
                    if (i<= args.length){
                        if (!isNumericZidai(arr.substring(i,i+1))){
                            System.out.println(i);
                            OBJECT.notify();
                            System.out.println(Thread.currentThread().getName()+arr.charAt(i));
                            i++;
                        }else {
                            try {
                                OBJECT.wait();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }else break;
                }
                OBJECT.notify();
            }
        },"B").start();

    }
    public static boolean isNumericZidai(String str) {
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    private static String arr="1A2B3C4D5E6F7G";
    private static int i=0;
    public static final Object OBJECT=new Object();
}
